package sig.web.struts.actions;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import sig.model.entities.SigUser;
import sig.util.IServices;


import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport implements SessionAware {

	private Map<String ,Object> session;
	private String password;
	private String login;
	private String message;
	private IServices services;
	
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("rawtypes")
	@Override
	public void setSession(Map arg0) {
		this.session = session;
		
	}
	public String execute() {
		return SUCCESS;
	}
	
	public String login(){
		SigUser user = services.authenticate(login, password);

		if (user == null) {
			setMessage("Ups..., ocurrió un error cuando intentaste iniciar sesión. Revisa tu login y contraseña.");
			return ERROR;
		} else {
			session.put("USER_SESSION", user);
		}

		return SUCCESS;
	}


	




	public String getPassword() {
		return password;
	}


	public void setPassword(String password) {
		this.password = password;
	}


	public String getLogin() {
		return login;
	}


	public void setLogin(String login) {
		this.login = login;
	}


	public String getMessage() {
		return message;
	}


	public void setMessage(String message) {
		this.message = message;
	}


	public IServices getServices() {
		return services;
	}


	public void setServices(IServices services) {
		this.services = services;
	}
	
	
}
